package com.epalmpay.controller.channel.datareport;

import com.epalmpay.commom.BaseController;
import com.epalmpay.dto.member.MemberInDTO;
import com.epalmpay.dto.member.MemberOutDTO;
import com.epalmpay.dto.trade.TradeInDTO;
import com.epalmpay.dto.trade.TradeOutDTO;
import com.epalmpay.entity.Member;
import com.epalmpay.entity.TradeOffline;
import com.epalmpay.entity.YsObd;
import com.epalmpay.entity.YsOilcardMember;
import com.epalmpay.exception.ApplicationException;
import com.epalmpay.service.datareport.IShopDataReportService;
import com.epalmpay.status.Rescode;
import com.epalmpay.util.PropertyCopyUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018/4/26.
 */
@Controller
@RequestMapping(value="/merchant/subMerchantReport")
public class SubMerchantReportController extends BaseController {

    @Resource
    private IShopDataReportService shopDataReportService;

    @RequestMapping(value="/shopTradeData")
    @ResponseBody
    public List list(){
        Map map = new HashMap();
        map.put("groupId",getRequest().getParameter("groupid"));
        map.put("searchkey",getRequest().getParameter("searchkey")+"-00");
        map.put("payType","null".equals(getRequest().getParameter("payType"))?null:getRequest().getParameter("payType"));
        map.put("shopId", "null".equals(getRequest().getParameter("shopid"))?null:getRequest().getParameter("shopid"));
        map.put("transactionType",getRequest().getParameter("transactionType"));
        map.put("transactionStatus",getRequest().getParameter("transactionStatus"));
        List result = new ArrayList();
        try {

            result = shopDataReportService.shopTradeData(map);
        } catch (ApplicationException ae) {
            result = null;
            ae.printStackTrace();
        } catch (Exception e) {
            result = null;
            e.printStackTrace();
        }
        System.out.println(result);
        return result;
    }


    /**
     *根据groupid、门店和查询日期获取统计数据
     *
     */
    @RequestMapping(value="/shopDayTradeData")
    @ResponseBody
    public List shopDayTradeData(){
        Map param = new HashMap();
        param.put("groupId",getRequest().getParameter("groupid"));
        param.put("flag", getRequest().getParameter("flag"));
        param.put("shopId", getRequest().getParameter("shopid"));
        param.put("searchkey", getRequest().getParameter("searchkey"));
        return shopDataReportService.shopDayTradeData(param);
    }






    @RequestMapping(value="/shopOutData")
    @ResponseBody
    public TradeOutDTO shopOutData(TradeInDTO tradeInDTO){
        TradeOutDTO tradeOutDTO = new TradeOutDTO();
        try {

            tradeOutDTO=shopDataReportService.shopOutData(tradeInDTO);
            tradeOutDTO.setErrorCode(Rescode.SUCCESS, "查询成功");

        } catch (ApplicationException ae) {
            tradeOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }catch (Exception e) {
            tradeOutDTO.setErrorCode("-1", "处理出现异常");
            e.printStackTrace();
        }
        return tradeOutDTO;
    }





}
